//
//  Layer_GameAnimation.cpp
//  mytest
//
//  Created by 杨岑 on 7/23/14.
//
//

#include "Layer_GameBgAni.h"


bool Layer_GameBgAni::init()
{
    if (!super::init()) return false;
    
    Size mySize = this->getContentSize();
    //auto bg = LayerColor::create(Color4B(55, 66, 77, 255));
    //bg->setContentSize(mySize);
    //this->addChild(bg);
    
    return true;
}

void Layer_GameBgAni::onExit()
{
    
}

void Layer_GameBgAni::onEnter()
{
    super::onEnter();
    
    Size mySize = this->getContentSize();
    Point pos = Point(mySize.width / 2, mySize.height / 2);
    
    auto clippingNode = ClippingNode::create();
    //clippingNode->setContentSize(Size::ZERO); // Size is not important
    //clippingNode->setAlphaThreshold(0);
    this->addChild(clippingNode);
    
    auto stencil = LayerColor::create();
    stencil->setContentSize(mySize);    // Stencil size is critical
    CCASSERT(stencil, "SHOULD NOT BE NIL!");
    clippingNode->setStencil(stencil);
    
    Sprite* sprites[3];
    for (int i = 0; i < 3; i++)
    {
        char s[100];
        sprintf(s, "%03d.png", i + 1);
        sprites[i] = Sprite::create(s);
        Size size = sprites[i]->getContentSize();
        sprites[i]->setPosition(pos);
        sprites[i]->setColor(Color3B(77, 88, 99));
        sprites[i]->setScale(mySize.width / size.width, mySize.height / size.height);
        clippingNode->addChild(sprites[i], 3 - i);
    }
    
    auto rotation = RotateBy::create(0.5, 90);
    auto delay = DelayTime::create(3);
    auto sequence = Sequence::create(rotation, delay, NULL);
    auto repeat = RepeatForever::create(sequence);
    sprites[1]->runAction(repeat);
}

